<template>
	<view class="page">
		<!-- 招商经理 -->
		<u-form v-if="rowData.id==1" labelPosition="left" :model="leasingManager" :rules="rules" labelWidth="auto"
			ref="uForm">
			<u-form-item label="姓名" prop="name" borderBottom>
				<u-input v-model="leasingManager.name" border="none"></u-input>
			</u-form-item>
			<u-form-item label="电话" prop="phone" borderBottom>
				<u-input v-model="leasingManager.phone" border="none"></u-input>
			</u-form-item>
		</u-form>
		<!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
		<u-form v-else-if="rowData.id==3" labelPosition="left" :model="mallMuseum" :rules="rules" labelWidth="auto"
			ref="uForm">
			<u-form-item label="博物馆门头" prop="logo" borderBottom labelPosition="top">
				<u-upload :fileList="mallMuseum.logo" @afterRead="afterRead" @delete="deletePic" name="1" multiple
					:maxCount="1" :previewFullImage="true"></u-upload>
			</u-form-item>
			<u-form-item label="博物馆名称" prop="name" borderBottom>
				<u-input v-model="mallMuseum.name" border="none"></u-input>
			</u-form-item>
			<u-form-item label="博物馆简称" prop="shortName" borderBottom>
				<u-input v-model="mallMuseum.shortName" border="none"></u-input>
			</u-form-item>
			<u-form-item label="营业执照照片" prop="zhidao" borderBottom labelPosition="top">
				<u-upload :fileList="mallMuseum.zhidao" @afterRead="afterRead" @delete="deletePic" name="1" multiple
					:maxCount="1" :previewFullImage="true"></u-upload>
			</u-form-item>
			<u-form-item label="信用代码" prop="xinyongcode" borderBottom>
				<u-input v-model="mallMuseum.xinyongcode" border="none"></u-input>
			</u-form-item>
			<u-form-item label="详细地址" prop="address" borderBottom>
				<u-input v-model="mallMuseum.address" border="none"></u-input>
			</u-form-item>
			<u-form-item label="营业时间" prop="openTime" borderBottom>
				<u-input v-model="mallMuseum.openTime" border="none"></u-input>
			</u-form-item>
			<u-form-item label="联系电话" prop="phone" borderBottom>
				<u-input v-model="mallMuseum.phone" border="none"></u-input>
			</u-form-item>
			<u-form-item label="详情介绍" prop="descript" borderBottom labelPosition="top">
				<u--textarea v-model="mallMuseum.descript" placeholder="请输入详情介绍"></u--textarea>
			</u-form-item>

			<u-form-item label="审核状态" prop="status" borderBottom>
				<u-input v-model="mallMuseum.status" border="none"></u-input>
			</u-form-item>
		</u-form>
		<u-form v-else-if="rowData.id == 9" labelPosition="left" :model="marketEntry" :rules="rules" labelWidth="auto" ref="uForm">
		</u-form>
		<u-form v-else labelPosition="left" :model="marketEntry" :rules="rules" labelWidth="auto" ref="uForm">
			<u-form-item label="公司logo" prop="logo" borderBottom>
				<!-- <u-input v-model="marketEntry.logo" border="none"></u-input> -->
				<u-upload :fileList="marketEntry.logo" @afterRead="afterRead" @delete="deletePic" name="1" multiple
					:maxCount="1" :previewFullImage="true"></u-upload>
			</u-form-item>
			<u-form-item label="公司名称" prop="name" borderBottom>
				<u-input v-model="marketEntry.name" border="none"></u-input>
			</u-form-item>
			<u-form-item label="公司简称" prop="shortName" borderBottom>
				<u-input v-model="marketEntry.shortName" border="none"></u-input>
			</u-form-item>
			<u-form-item label="联系电话" prop="phone" borderBottom>
				<u-input v-model="marketEntry.phone" border="none"></u-input>
			</u-form-item>
			<u-form-item label="营业执照" prop="zhizhao" borderBottom labelPosition="top">
				<!-- <u-input v-model="marketEntry.zhizhao" border="none"></u-input> -->
				<u-upload :fileList="marketEntry.zhizhao" @afterRead="afterRead" @delete="deletePic" name="6" multiple
					:maxCount="1" width="250" height="150">
					<image src="https://cdn.uviewui.com/uview/demo/upload/positive.png" mode="widthFix"
						style="width: 250px;height: 150px;"></image>
				</u-upload>
			</u-form-item>
			<u-form-item label="信用代码" prop="xinyongCode" borderBottom>
				<u-input v-model="marketEntry.xinyongCode" border="none"></u-input>
			</u-form-item>
			<u-form-item label="详细地址" prop="address" borderBottom>
				<u-input v-model="marketEntry.address" border="none"></u-input>
			</u-form-item>
			<u-form-item label="营业时间" prop="openTime" borderBottom>
				<u-input v-model="marketEntry.openTime" border="none"></u-input>
			</u-form-item>
			<u-form-item label="介绍" prop="description" borderBottom labelPosition="top">
				<u--textarea v-model="marketEntry.description" placeholder="请输入详情介绍"></u--textarea>
			</u-form-item>
			<u-form-item label="正面身份证照片" prop="id_number_picturce_1" borderBottom labelPosition="top">
				<!-- <u-input v-model="marketEntry.id_number_picturce_1" border="none"></u-input> -->
				<u-upload :fileList="marketEntry.id_number_picturce_1" @afterRead="afterRead" @delete="deletePic"
					name="6" multiple :maxCount="1" width="250" height="150">
					<image src="https://cdn.uviewui.com/uview/demo/upload/positive.png" mode="widthFix"
						style="width: 250px;height: 150px;"></image>
				</u-upload>
			</u-form-item>
			<u-form-item label="反面身份证照片" prop="id_number_picturce_2" borderBottom labelPosition="top">
				<!-- <u-input v-model="marketEntry.id_number_picturce_2" border="none"></u-input> -->
				<u-upload :fileList="marketEntry.id_number_picturce_2" @afterRead="afterRead" @delete="deletePic"
					name="6" multiple :maxCount="1" width="250" height="150">
					<image src="https://cdn.uviewui.com/uview/demo/upload/positive.png" mode="widthFix"
						style="width: 250px;height: 150px;"></image>
				</u-upload>
			</u-form-item>
			<u-form-item label="法人姓名" prop="farenName" borderBottom>
				<u-input v-model="marketEntry.farenName" border="none"></u-input>
			</u-form-item>
			<u-form-item label="身份证号" prop="idNumber" borderBottom>
				<u-input v-model="marketEntry.idNumber" border="none"></u-input>
			</u-form-item>
			<u-form-item label="收款人" prop="payee" borderBottom>
				<u-input v-model="marketEntry.payee" border="none"></u-input>
			</u-form-item>
			<u-form-item label="开户银行" prop="bankOfDeposit" borderBottom>
				<u-input v-model="marketEntry.bankOfDeposit" border="none"></u-input>
			</u-form-item>
			<u-form-item label="银行卡号" prop="bankCardNumber" borderBottom>
				<u-input v-model="marketEntry.bankCardNumber" border="none"></u-input>
			</u-form-item>
			<u-form-item label="招商经理" prop="leasingManager" borderBottom @click="showLeasingManager = true">
				<u-input v-model="marketEntry.leasingManager" border="none" disabled disabledColor="#ffffff"
					placeholder="请选择招商经理"></u-input>
			</u-form-item>
			<u-form-item label="入住费用" prop="checkInFee" borderBottom>
				<u-input v-model="marketEntry.checkInFee" border="none"></u-input>
			</u-form-item>
			<u-form-item label="审核状态" prop="status" borderBottom>
				<u-input v-model="marketEntry.status" border="none"></u-input>
			</u-form-item>

		</u-form>

		<u-action-sheet :show="showLeasingManager" :actions="actions" title="请选择招商经理"
			@close="showLeasingManager = false" @select="sexSelect">
		</u-action-sheet>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showLeasingManager: false,
				actions: [{
						name: '无',
					},
					{
						name: '周海军',
					},
					{
						name: '某某人',
					},
				],
				rules: {
					'userInfo.name': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
					'userInfo.sex': {
						type: 'string',
						max: 1,
						required: true,
						message: '请选择男或女',
						trigger: ['blur', 'change']
					},
				},
				radio: '',
				switchVal: false,

				// 商户类型
				rowData: null,
				// 招商经理入驻
				leasingManager: {
					name: '',
					phone: ''
				},
				// 全国艺术品市场区域代理入驻
				regionalManager: {
					phone: '',
					IDList: [],
					name: '',
					idNumber: '',
					proxyType: '',
					entryFee: '',
					payee: '',
					bankOfDeposit: '',
					bankID: ''
				},
				// 博物馆入驻
				mallMuseum: {
					logo: null,
					name: '',
					shortName: '',
					address: '',
					openTime: '',
					phone: '',
					descript: '',
					zhidao: null,
					xinyongcode: '',
					status: ''
				},
				// 市场入驻、商户入驻（通过parentId判断）
				marketEntry: {
					parentId: '',
					logo: [{
						url: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
					}],
					name: '',
					shortName: '',
					phone: '',
					zhizhao: '',
					xinyongCode: '',
					address: '',
					openTime: '',
					description: '',
					id_number_picturce_1: null,
					id_number_picturce_2: null,
					farenName: '',
					idNumber: '',
					payee: '',
					bankOfDeposit: '',
					bankCardNumber: '',
					leasingManager: '无',
					checkInFee: '',
					status: ''
				},

				// 基础表单数据
				baseFormData: {
					a: '',
					name: '',
					phone: ''
				},
				// 是否靠前
				cityData: [{
					text: "是",
					value: "1",
				}, {
					text: "否",
					value: "0",
				}]

			}
		},
		onLoad(option) {
			console.log(option);
			this.rowData = option;
			uni.setNavigationBarTitle({
				title: this.rowData.name + "入驻"
			});
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)
		},
		methods: {
			// 图片上传
			// 删除图片
			deletePic(event) {
				this.marketEntry.logo.splice(event.index, 1);
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
			sexSelect(e) {
				this.marketEntry.leasingManager = e.name;
				// this.$refs.uForm.validateField('userInfo.sex')
			},
			onClickItem(e) {
				console.log(e);
				this.current = e.currentIndex
			},
			add() {
				this.dynamicFormData.domains.push({
					label: '域名',
					value: '',
					rules: [{
						'required': true,
						errorMessage: '域名项必填'
					}],
					id: Date.now()
				})
			},
			del(id) {
				let index = this.dynamicLists.findIndex(v => v.id === id)
				this.dynamicLists.splice(index, 1)
			},
			submit(ref) {
				console.log(this.baseFormData);
				this.$refs[ref].validate().then(res => {
					console.log('success', res);
					uni.showToast({
						title: `校验通过`
					})
				}).catch(err => {
					console.log('err', err);
				})
			},
		}
	}
</script>

<style lang="scss">
	@import 'privateMuseumOccupancy.scss';
	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		line-height: 35px;
		margin-left: 10px;
	}
</style>